package com.example.stringbufferlogger.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.stringbufferlogger.entity.InterfaceMappingConfig;
import com.example.stringbufferlogger.entity.LogRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface InterfaceMappingConfigMapper extends BaseMapper<InterfaceMappingConfig> {

    String getNewPath(String oldPath);

    @Select("SELECT * FROM INTERFACE_MAPPING_CONFIG WHERE old_path = #{interfaceUrl} OR new_path = #{interfaceUrl}")
    InterfaceMappingConfig selectByInterfaceUrl(String interfaceUrl);
    @Select("SELECT new_path FROM INTERFACE_MAPPING_CONFIG WHERE old_path = #{interfaceUrl}")
    String selectByOldpath(String interfaceUrl);;

    /**
     * 根据 interfaceUrl 判断是 old_path 还是 new_path
     * @param interfaceUrl 接口 URL
     * @return 如果匹配 old_path 返回 "old"，匹配 new_path 返回 "new"，都不匹配返回 null
     */
    @Select("SELECT CASE " +
            "WHEN old_path = #{interfaceUrl} THEN 'old' " +
            "WHEN new_path = #{interfaceUrl} THEN 'new' " +
            "ELSE NULL " +
            "END " +
            "FROM INTERFACE_MAPPING_CONFIG " +
            "WHERE old_path = #{interfaceUrl} OR new_path = #{interfaceUrl}")
    String checkPathType(String interfaceUrl);
}
